# coding=utf-8
# Date: 2021/9/23 9:52
from typing import List


# 执行用时：196 ms, 在所有 Python3 提交中击败了24.57%的用户
# 内存消耗：16.6 MB, 在所有 Python3 提交中击败了70.58%的用户
class Solution:
    def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
        res, p = 0, 1
        i, j = 0, 0
        while i < len(nums):
            p *= nums[i]
            while j <= i and p >= k:
                p //= nums[j]
                j += 1
            res += i - j + 1
            i += 1
        return res


if __name__ == "__main__":
    print(Solution().numSubarrayProductLessThanK([10, 5, 2, 6], 100))
